<?php
/**
 * PsiFramework
 *
 * Php Simple Framework
 *
 * PHP version 5.3
 *
 * @category  PsiFramework.Plugins.Form.Classes.Model
 * @package   PsiFramework.Plugins.Form.Classes.Model
 * @author    Remi San <remi.san@gmail.com>
 * @copyright 2011 Remi San
 * @license   http://creativecommons.org/licenses/by/3.0/  Creative Commons CC BY 3.0
 * @version   SVN: <svn_id>
 * @link      http://www.psiframework.com/phpdoc/classes/db_\PsiFramework\Plugins\Form\Classes\Model\Form.html
 */

namespace PsiFramework\Plugins\Form\Classes\Model;

import("Classes.Model.Object");
import("Plugins.Form.Classes.Model.FormFieldLink");
import("Plugins.Form.Classes.Util.Json.JsonForm");
import("Classes.Util.Parameters.ObjectParameters");

use \PsiFramework\Classes\Model\Object;
use \PsiFramework\Plugins\Form\Classes\Model\FormFieldLink;
use \PsiFramework\Plugins\Form\Classes\Util\Json\JsonForm;
use \PsiFramework\Classes\Util\Parameters\ObjectParameters;
use \PsiFramework\Classes\Util\Object\Date;

/**
 * The Form Object
 *
 * This is the class for the Form Object
 *
 * @category PsiFramework.Plugins.Form.Classes.Model
 * @package  PsiFramework.Plugins.Form.Classes.Model
 * @author   Remi San <remi.san@gmail.com>
 * @license  http://creativecommons.org/licenses/by/3.0/  Creative Commons CC BY 3.0
 * @link     http://www.psiframework.com/phpdoc/classes/db_\PsiFramework\Plugins\Form\Classes\Model\Form.html
 */
class Form extends Object
{

    /**
     * @var int
     */
    protected /*int*/              $_id ;
    /**
     * @var string
     */
    protected /*string*/           $_name ;
    /**
     * @var string
     */
    protected /*string*/           $_title ;
    /**
     * @var array
     */
    protected /*FormFieldLink[]*/  $_fields ;
    /**
     * @var JsonForm
     */
    protected /*JsonForm*/         $_structure ;
    /**
     * @var ObjectParameters
     */
    protected /*ObjectParameters*/ $_responseParameters ;
    /**
     * @var Date
     */
    protected /*Date*/             $_creationDate;
    /**
     * @var Date
     */
    protected /*Date*/             $_modificationDate;

    /**
     * Constructor
     * 
     * @param int              $id                 The id
     * @param string           $name               The name
     * @param string           $title              The title
     * @param array            $fields             The fields
     * @param JsonForm         $structure          The structure
     * @param ObjectParameters $responseParameters The response parameters
     * 
     * @return Form
     */
    public function __construct(
        /*int*/             $id=null,
        /*string*/          $name=null,
        /*string*/          $title=null,
        /*FormFieldLink[]*/ $fields=null,
        JsonForm            $structure=null,
        ObjectParameters    $responseParameters=null
    )
    {
        $this->_id = $id ;
        $this->_name = $name ;
        $this->_title = $title ;
        $this->_fields = $fields ;
        $this->_structure = $structure ;
        $this->_responseParameters = $responseParameters ;
    }

    /**
     * Getter for the id / primary key
     *
     * @see Object::getId()
     *
     * @return int
     */
    public function getId()
    {
        return $this->_id ;
    }

    /**
     * Setter for the id
     *
     * @param int $id The id
     *
     * @return void
     */
    public function setId(/*int*/ $id)
    {
        $this->_id = $id ;
    }

    /**
     * Getter for the name
     *
     * @return string
     */
    public function getName()
    {
        return $this->_name ;
    }

    /**
     * Setter for the name
     *
     * @param string $name The name
     *
     * @return void
     */
    public function setName(/*string*/ $name)
    {
        $this->_name = $name ;
    }
    
    /**
     * Getter for the title
     *
     * @return string
     */
    public function getTitle()
    {
    	return $this->_title ;
    }
    
    /**
     * Setter for the title
     *
     * @param string $title The title
     *
     * @return void
     */
    public function setTitle(/*string*/ $title)
    {
    	$this->_title = $title ;
    }

    /**
     * Getter for the fields
     *
     * @return array
     */
    public function getFields()
    {
        $this->sortFields();
    	return $this->_fields ;
    }

    /**
     * Setter for the fields
     *
     * @param array $fields The fields
     *
     * @return void
     */
    public function setFields(/*FormFieldLink[]*/ $fields)
    {
        $this->_fields = $fields ;
        $this->sortFields();
    }

    /**
     * The function to add a FormFieldLink
     * 
     * @param FormFieldLink $field The field link
     * 
     * @return void
     */
    public function addFields(/*FormFieldLink*/ $field)
    {
        if (is_null($this->_fields)) {
            $this->_fields = array();
        }
        $this->_fields[] = $field ;
    }

    /**
     * The function to sort the fields
     * 
     * @return array
     */
    public function sortFields()
    {
    	if (!is_null($this->_fields)) {
        	ksort($this->_fields);
        };
        return $this->_fields ;
    }

    /**
     * Getter for the structure
     *
     * @return jsonForm
     */
    public function getStructure()
    {
        return $this->_structure ;
    }

    /**
     * Setter for the structure
     *
     * @param JsonForm $structure The structure
     *
     * @return void
     */
    public function setStructure(JsonForm $structure)
    {
        $this->_structure = $structure ;
    }

    /**
     * Getter for the response parameters
     *
     * @return ObjectParameters
     */
    public function getResponseParameters()
    {
        return $this->_responseParameters ;
    }

    /**
     * Setter for the response parameters
     *
     * @param ObjectParameters $responseParameters The response parameters
     *
     * @return void
     */
    public function setResponseParameters(
        ObjectParameters $responseParameters
    )
    {
        $this->_responseParameters = $responseParameters ;
    }

    /**
     * Getter for the creation date
     *
     * @return Date
     */
    public function getCreationDate()
    {
        return $this->_creationDate ;
    }

    /**
     * Setter for the creation date
     * 
     * @param Date $creationDate The creation date
     * 
     * @return void
     */
    public function setCreationDate(Date $creationDate)
    {
        $this->_creationDate = $creationDate ;
    }

    /**
     * Getter for the modification date
     *
     * @return Date
     */
    public function getModificationDate()
    {
        return $this->_modificationDate ;
    }

    /**
     * Setter for the modification date
     *
     * @param Date $modificationDate The modification date
     *
     * @return void
     */
    public function setModificationDate(Date $modificationDate)
    {
        $this->_modificationDate = $modificationDate ;
    }

    /**
     * Shows the Form as a string
     *
     * @see Object::toString()
     *
     * @return string
     */
    public function toString()
    {
        return $this->_title ;
    }

}
